<?php
require_once 'ExceptionHandler.php';
require_once 'LocalFileOperations.php';


/**
 * This example Unit Test tests only the main part of the code. We can add more tests as desired.
 * This test is based on PHPUnit
 * You may need to check the autoload paths set before executing this test
 * @author Sukhbir Singh Grewal
 *
 */	
class SampleUnitTest extends PHPUnit_Framework_TestCase  
{  
	private $lf;
	private $correct_folder = 'c:'; //OR maybe '/home/user' on *nix systems
	private $wrong_folder = 'c:\tweryu';	//incorrect folder to test - folder does not exist OR insufficient permissions on folder etc.

	public function setUp()
	{				
		$this->lf = new LocalFileOperations();
	}
	public function tearDown(){ }
	
	public function testListContents()
	{	
		$contents = $this->lf->listContents($this->correct_folder);
		$this->assertNotNull($contents);
		foreach ($contents as $item)
		{
			$info = $item->getInfo();
			$this->assertArrayHasKey('name', $info);
			$this->assertArrayHasKey('isDir', $info);
			$this->assertArrayHasKey('absolutePath', $info);
			$this->assertArrayHasKey('filesize', $info);
		}
		try {            
            $this->lf->listContents($this->wrong_folder);	//Code that is expected to raise an exception
        }
        catch (ExceptionHandler $expected) {
            return;	//ignore as this is expected
        } 
        $this->fail('An expected exception has not been raised for incorrect folder');		
	}
	
}